package com.hjl.service.impl;

import com.hjl.dao.DeptDao;
import com.hjl.dao.impl.DeptDaoImpl;
import com.hjl.domain.Dept_inf;
import com.hjl.domain.PageBean;
import com.hjl.service.DeptService;
import java.util.List;
import java.util.Map;

/**
 * 部门业务逻辑层实现类
 *
 * @author Lenovo
 * @version 1.0
 * @date 2021/10/8 20:35
 */
public class DeptServiceImpl implements DeptService {
    private DeptDao deptDao = new DeptDaoImpl();

    /**
     * 分页查询
     *
     * @param currentPageString 当前页
     * @param rowsString        行数
     * @param condition         状态
     * @return com.hjl.domain.PageBean<com.hjl.domain.Dept_inf>
     * @author Lenovo
     * @date 2021/10/8 20:38
     */
    @Override
    public PageBean<Dept_inf> findDeptByPage(String currentPageString, String rowsString, Map<String, String[]> condition) {
        int currentPage = Integer.parseInt(currentPageString);
        int rows = Integer.parseInt(rowsString);
        int totalCount = deptDao.findTotalCount(condition);
        int start = (currentPage - 1) * rows;
        List<Dept_inf> list = deptDao.findByPage(start, rows, condition);
        int totalPage = totalCount % rows == 0 ? totalCount / rows : (totalCount / rows + 1);

        //创建PageBean并放入数据，返回
        return new PageBean<>(totalCount, totalPage, list, currentPage, rows);
    }

    /**
     * 删除选中
     *
     * @param ids 选中的id
     * @author Lenovo
     * @date 2021/10/8 20:38
     */
    @Override
    public void delSelect(String[] ids) {
        if (ids != null && ids.length > 0) {
            for (String id : ids) {
                deptDao.delDept(Integer.parseInt(id));
            }
        }
    }

    /**
     * 更新
     *
     * @param dept 部门对象
     * @author Lenovo
     * @date 2021/10/8 20:38
     */
    @Override
    public void updateDept(Dept_inf dept) {
        deptDao.updateDept(dept);
    }

    /**
     * 通过id查询
     *
     * @param id ID
     * @return com.hjl.domain.Dept_inf
     * @author Lenovo
     * @date 2021/10/8 20:39
     */
    @Override
    public Dept_inf findDeptById(String id) {
        return deptDao.findDeptById(Integer.parseInt(id));
    }

    /**
     * 添加
     *
     * @param dept 部门对象
     * @author Lenovo
     * @date 2021/10/8 20:39
     */
    @Override
    public void addDept(Dept_inf dept) {
        deptDao.addDept(dept);
    }
}
